//
//  JMLoginViewMode.m
//  VoluntaryStar
//
//  Created by xiaorui on 15/9/1.
//  Copyright (c) 2015年 ios. All rights reserved.
//

#import "JMLoginViewMode.h"
#import "JMAppNetworkClient.h"
#import "JMUser.h"

@implementation JMLoginViewMode

+ (void) fetchLoginMessageParametes:(NSDictionary *)dict  block:(ReturnBackMessage)block{
   
    [JMAppNetworkClient postLoginWithInfo:dict compelete:^(id data, NSError *error) {
        
        NSMutableDictionary *downDict = (NSMutableDictionary *)data;
        NSLog(@"%@",data);
        if([[downDict objectForKey:@"status"] integerValue] == 1){
            JMUser *user = [[JMUser alloc]init];
            user.message = [downDict objectForKey:@"message"];
            user.state = [NSString stringWithFormat:@"%@",[downDict objectForKey:@"status"]];
            user.token = [downDict objectForKey:@"token"];
            user.userId = [NSString stringWithFormat:@"%@",[downDict objectForKey:@"user"]];
            user.email = [NSString stringWithFormat:@"%@",downDict[@"userinfo"][@"email"]];
            user.lastTime = [NSString stringWithFormat:@"%@",downDict[@"userinfo"][@"lasttime"]];
            user.mobile = [NSString stringWithFormat:@"%@",downDict[@"userinfo"][@"mobile"]];
            user.regTime = [NSString stringWithFormat:@"%@",downDict[@"userinfo"][@"regtime"]];
            user.dizhi = downDict[@"userinfo"][@"city"];
            user.grade = downDict[@"userinfo"][@"grade"];
            user.nicheng = downDict[@"userinfo"][@"login"];
            user.schoolString = downDict[@"userinfo"][@"mschool"];
            user.picString = downDict[@"userinfo"][@"pic"];
            user.sexString = [NSString stringWithFormat:@"%@",downDict[@"userinfo"][@"sex"]];
            user.weixin = [NSString stringWithFormat:@"%@",downDict[@"userinfo"][@"wenli"]];

            //获得Document的路径
            NSString *documents = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
            NSString *path = [documents stringByAppendingPathComponent:@"person.archiver"];//拓展名可以自己随便取
            
            [NSKeyedArchiver archiveRootObject:user toFile:path];
            block(data,error,user);
            
           
        }else{
            block(data,error,nil);
        }
    }];
}

@end
